package com.amlyc.demo1;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread2 extends Thread {

    private String url;
    private String name;

    public TestThread2(String url, String name) {
        this.url=url;
        this.name=name;
    }

    @Override
    public void run() {
        WebDownloader webDownloader = new WebDownloader();
        webDownloader.downloader(url,name);
        System.out.println("name:"+name);
    }

    public static void main(String[] args) {
        TestThread2 testThread1 = new TestThread2("https://blog.kuangstudy.com/usr/themes/PureLoveForTypecho/images/banner1.jpg", "1.jpg");
        TestThread2 testThread2 = new TestThread2("https://blog.kuangstudy.com/usr/themes/PureLoveForTypecho/images/banner1.jpg", "2.jpg");
        TestThread2 testThread3 = new TestThread2("https://blog.kuangstudy.com/usr/themes/PureLoveForTypecho/images/banner1.jpg", "3.jpg");
        testThread1.start();
        testThread2.start();
        testThread3.start();
    }
}
class WebDownloader{

    public void downloader(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}